// pages/order/order.js
const db = wx.cloud.database()
const account = wx.getStorageSync('userInfo').account
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navTitle:['待付款','待配送','待收货','全部'],
    currentNavid:0
  },

  onShow(){
    if(app.golbalData.isLogin) this.init()
  },

  changeToActive(e){
    this.setData({
      currentNavid:e.currentTarget.id
    })
  },

  changePages(e){
    this.setData({
      currentNavid:e.detail.currentItemId
    })
  },

  //数据初始化
  init(){
    db.collection('orders').where({
      account,
    }).get().then(res=>{
      let waitPayment = res.data.filter((item)=>{
        return item.state.indexOf('待付款') !== -1
      })
      let waitDelivery = res.data.filter((item)=>{
        return item.state.indexOf('待配送') !== -1
      })
      let waitReceive = res.data.filter((item)=>{
        return item.state.indexOf('待收货') !== -1
      })

      this.setData({
        allOrders:res.data,
        waitPayment,
        waitDelivery,
        waitReceive,
      })
    })
  }
})